package com.android.lovely.ui.dialog

import androidx.fragment.app.viewModels
import com.android.lovely.R
import com.android.lovely.aav.PreferentialManager
import com.android.lovely.aav.PreferentialManager.playImage
import com.android.lovely.databinding.DialogPreferentialBinding
import com.android.lovely.framework.BaseDialogFragment
import com.android.lovely.framework.UIController.showToast
import com.android.lovely.manager.KVStore
import com.android.lovely.ui.viewmodel.PayViewModel
import com.kotlin.extensions.view.ViewExt.clickable

class PreferentialDialog : BaseDialogFragment<DialogPreferentialBinding>() {

    val viewModel by viewModels<PayViewModel>()
    override fun initializeViews() {
        isCancelable = false
        val info = PreferentialManager.product
        val subActive = PreferentialManager.firstActive
        if (!PreferentialManager.isEnable || info == null || subActive == null) {
            dismiss()
            return
        }
        KVStore.discountShowTime = System.currentTimeMillis()
        binding.close.clickable {
            PersuasionDialog().show(parentFragmentManager)
            dismiss()
        }
        binding.image.playImage()

        binding.image.clickable {
            viewModel.pay(requireActivity(), info){
                dismissAllowingStateLoss()
            }
        }
    }
}